package com.example.springboot.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import com.example.springboot.pojo.Announcement;
import com.example.springboot.service.AnnouncementService;
import com.example.springboot.pojo.Result;
@RestController
@RequestMapping("/Announcement")
@CrossOrigin
public class AnnouncementController {
    @Autowired
    private AnnouncementService announcementService;
    @PostMapping("/create")
    public Result create(@RequestBody Announcement announcement)
    {
        announcementService.create(announcement);
        return Result.success();
    }
    @DeleteMapping("/delete")
    public Result delete(Integer id)
    {
        announcementService.delete(id);
        return Result.success();
    }
    @PostMapping("/update")
    public Result update(@RequestBody Announcement announcement)
    {
        announcementService.update(announcement);
        return Result.success();
    }

    @GetMapping("/getAll")
    public Result findAll()
    {
        List<Announcement> list = announcementService.findAll();
        return Result.success(list);
    }
    @GetMapping("/findByTitle")
    public Result findByTitle(@RequestParam String title)
    {
        List<Announcement> list = announcementService.findByTitle(title);
        return Result.success(list);
    }
    @GetMapping("/selectPage")
    public Result selectPage(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize) {
        return Result.success(announcementService.selectPage(pageNum, pageSize));
    }
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        announcementService.deleteBatch(ids);
        return Result.success();
    }
    @GetMapping("/findById")
    public Result findById(Integer id) {
        return Result.success(announcementService.findById(id));
    }

}
